package com.az.usr.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.az.miaoapi.dto.MUserDto;
import com.az.miaoapi.exception.BaseException;
import com.az.servicecommon.domain.NullVo;
import com.az.servicecommon.domain.Vo;
import com.az.servicecommon.util.BaseResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.retry.annotation.Retryable;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.security.Principal;

@BaseResponse
@RestController
@RequestMapping("/usr")
@RequiredArgsConstructor
public class MUserController {
    private final RabbitTemplate rabbitTemplate;
    @PostMapping("/mupdate")
    @Retryable(noRetryFor = BaseException.class)
    @SentinelResource("mupdate")
    @PreAuthorize("hasAnyAuthority({'loginUser'})")
    public Vo mupdate(MUserDto mUserDto) {
        rabbitTemplate.convertAndSend("muser.direct", "mupdate_key", mUserDto);

        return new NullVo();
    }

    @PostMapping("/mget")
    @Retryable(noRetryFor = BaseException.class)
    @SentinelResource("mget")
    @PreAuthorize("hasAnyAuthority({'loginUser'})")
    public Vo mupdate(Principal principal) {
        // TODO

        return new NullVo();
    }
}
